<template>
  <div class="container"
       v-title
       data-title='个人中心'>
    <Person_top></Person_top>
    <div class="total-commission">
      <h3>
        <a href="javascript:;"
           v-on:click="turnPresimes">
          佣金总额数<small>（元）</small><br /><strong>{{customer.totalAmount.toFixed(2)}}</strong>
        </a>
      </h3>
      <div class="commission-bottom">
        <a href="javascript:;"
           class="col-sm-6"
           v-on:click="turnPresimes">
          已结佣<small>（元）</small><br /><strong>{{customer.hasbalance.toFixed(2)}}</strong>
        </a>
        <a href="javascript:;"
           class="col-sm-6"
           v-on:click="turnPresimes">
          待结佣<small>（元）</small><br /><strong>{{customer.hasnobalance.toFixed(2)}}</strong>
        </a>
      </div>
    </div>
    <!--
        	作者：353895897@qq.com
        	时间：2017-03-17
        	描述：合作协议去掉,需求原型上无此内容
        -->
    <!--
		<div class="line bor-b"></div>
		<ul class="ul-list-view list-view-icon-right">
			<li class="ul-list-view-cell pT14 pB14">
				<a href="javascript:;" class="list-navigate-right">
					<i class="fa fa-file-text-o my-icon"></i>
					合作协议
				</a>
			</li>
		</ul>
		-->
    <div class="line bor-b"></div>
    <ul class="ul-list-view list-view-icon-right">
      <li class="ul-list-view-cell pT14 pB14">
        <a href="javascript:;"
           class="list-navigate-right"
           v-on:click="changePwd">
          <i class="fa fa-unlock-alt my-icon fa-fw"
             aria-hidden="true"></i>
          修改密码
        </a>
      </li>
    </ul>
    <ul class="ul-list-view list-view-icon-right"
        v-if="!isShow">
      <li class="ul-list-view-cell pT14 pB14">
        <a href="javascript:;"
           class="list-navigate-right"
           v-on:click="bindCompany">
          <i class="fa fa-handshake-o my-icon fa-fw"
             aria-hidden="true"></i>
          绑定公司
        </a>
      </li>
    </ul>
    <ul class="ul-list-view list-view-icon-right"
        v-if="isShow">
      <li class="ul-list-view-cell pT14 pB14">
        <a href="javascript:;">
          <i class="fa fa-square-o my-icon fa-fw"></i>
          <!--公司代码<input v-model="company.companyCode" style="float: right;text-align: right;" readonly />-->
          公司代码<span style="float:right;">{{company.companyCode}}</span>
        </a>
      </li>
    </ul>
    <ul class="ul-list-view list-view-icon-right"
        v-if="isShow">
      <li class="ul-list-view-cell pT14 pB14">
        <a href="javascript:;">
          <i class="fa fa-camera-retro my-icon fa-fw"
             aria-hidden="true"></i>
          <!--所属公司<input v-model="company.companyName" style="float: right;text-align: right;" readonly />-->
          所属公司<span style="float:right;">{{company.companyName}}</span>
        </a>
      </li>
    </ul>
    <ul class="ul-list-view list-view-icon-right"
        v-if="principalName">
      <li class="ul-list-view-cell pT14 pB14">
        <a href="javascript:;">
          <i class="fa fa-camera-retro my-icon fa-fw"
             aria-hidden="true"></i>
          <!--所属公司<input v-model="company.companyName" style="float: right;text-align: right;" readonly />-->
          渠道支持<span style="float:right;">{{principalName}} {{principalPhone}}</span>
        </a>
      </li>
    </ul>
    <ul class="ul-list-view  mT120 bor-t">
      <li class="ul-list-view-cell pT14 pB14 trC"
          v-on:click="quit">
        <a href="javascript:;">
          退出登录
        </a>
      </li>
    </ul>
  </div>
</template>
<script>
import Person_top from "../common/person_top.vue";
export default {
  inject: ["reload"],
  data() {
    return {
      customer: {
        totalAmount: 0,
        hasbalance: 0,
        hasnobalance: 0
      },
      company: {
        companyCode: "",
        companyName: "",
        status: ""
      },
      isShow: false,
      principalName: "",
      principalPhone: ""
    };
  },
  components: {
    Person_top
  },
  mounted: function () {
    //初始化数据
    this.getPartnerInfo();
    this.initCustomerInfo();
    $("#goble_menu_div").show();
  },
  methods: {
    bindCompany: function () {
      this.$router.push({ name: "BindCompany" });
    },
    initCustomerInfo: function () {
      var _self = this;
      var body = {};
      body.params = {
        isturn: false
      };
      var url = this.utilHelper.apiUrl + "/api/getCustomerPremises";
      _self.$http.post(url, body).then((response) => {
        var body = response.body;
        if (body.result == 1) {
          _self.customer.totalAmount = body.resData.totalAmount;
          _self.customer.hasbalance = body.resData.hasbalance;
          _self.customer.hasnobalance = body.resData.hasnobalance;
        } else {
          // layer.msg("数据获取失败");
        }
      });
    },
    changePwd: function () {
      console.log(11111);
      this.$router.replace({
        path: "/changepwd"
      });
    },
    quit: function () {
      var _self = this;
      var body = {};
      var params = { userId: window.localStorage.getItem("3_userId") };
      body.params = params;
      var url = _self.utilHelper.apiUrl + "/api/loginOut";
      _self.$http.post(url, body).then(
        (response) => {
          var data = response.body;
          var result = data.result;
          var resData = data.resData;
          window.localStorage.removeItem("3_isLogin");
          window.localStorage.removeItem("3_userId");
          window.localStorage.removeItem("3_phone");
          window.localStorage.removeItem("3_password");
          //					_self.$router.replace({
          //						path: '/login'
          //					})
          _self.indexForward();
        },
        (response) => {}
      );
    },
    indexForward() {
      var _self = this;
      var body = {};
      body.params = {};
      var url = this.utilHelper.apiUrl + "/api/getAgencyIndexSwitch";
      _self.$http.post(url, body).then((response) => {
        var data = response.body.resData;
        var result = data.agencyIndexSwitch;
        var agencyIndexSwitch = "1";
        if (result) {
          agencyIndexSwitch = result;
        }
        if ("0" == agencyIndexSwitch) {
          layer.closeAll();
          this.$router.replace({
            path: "/login"
          });
        } else if ("1" == agencyIndexSwitch) {
          layer.closeAll();
          this.reload();
          this.$router.replace({
            path: "/index"
          });
        }
      });
    },
    turnPresimes: function () {
      var _self = this;
      _self.$router.replace({
        path: "/commission"
      });
    },
    loadCompany: function () {
      //加载公司信息
      var _self = this;
      var body = {};
      body.params = {};
      var url = this.utilHelper.apiUrl + "/api/getCompanyByUserId";
      _self.$http.post(url, body).then((response) => {
        var body = response.body;
        if (body.result == 1) {
          _self.company = body.resData.company;
          if (_self.company.companyCode) {
            _self.isShow = true;
          }
          _self.principalName = body.resData.principalName;
          _self.principalPhone = body.resData.principalPhone;
        }
      });
    },
    //实时获取用户信息
    getPartnerInfo() {
      var _self = this;
      var body = {};
      body.params = {};
      var url = this.utilHelper.apiUrl + "/api/getUserById";
      _self.$http.post(url, body).then((response) => {
        var data = response.body;
        var result = data.result;
        if (result == "1") {
          window.localStorage.setItem("3_userId", data.resData.id);
          window.localStorage.setItem("3_userName", data.resData.accountName);
          window.localStorage.setItem("3_phone", data.resData.phone);
          window.localStorage.setItem("3_userRole", data.resData.userRoleId);
          _self.loadCompany();
        } else if (result == "-2") {
          _self.quit();
        }
      });
    }
  }
};
</script>
